package chapter20;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TestStuScore {
    public static void main(String[] args) {
        StuScore stu1 = new StuScore("张三", 350);
        StuScore stu2 = new StuScore("李四", 500);
        StuScore stu3 = new StuScore("王五", 280);

        //添加列表
        List<StuScore> stuScoreList = new ArrayList<>();
        stuScoreList.add(stu1);
        stuScoreList.add(stu2);
        stuScoreList.add(stu3);

        //排序
        Collections.sort(stuScoreList, new StuScoreComparator());

        //遍历输出
        toString(stuScoreList);

        //逆序排序
        Collections.reverse(stuScoreList);
        System.out.println();
        System.out.println("逆序排序后：");
        toString(stuScoreList);

        //显示成绩最高的学生
        System.out.println();
        StuScore maxScore = Collections.max(stuScoreList,new StuScoreComparator());
        System.out.println("成绩最高的学生："+maxScore.getStuName()+" "+"分数为："+maxScore.getScore());

    }
    public static void toString(List<StuScore> stuScoreList){
        for (StuScore item:stuScoreList
        ) {
            System.out.println("学生姓名："+item.getStuName()+" "+"成绩："+item.getScore());
        }
    }
}
